package com.cardvalue.sys.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cardvalue.sys.R;
import com.cardvalue.sys.entity.MoreListDto;

import java.util.ArrayList;
import java.util.List;

/**
 * 更多页面的adapter
 * Created by cardvalue on 2016/4/1.
 */
public class MoreAdapter extends BaseAdapter{
    private List<MoreListDto> mMoreListDto= new ArrayList<>();
    private Context context;
    private LayoutInflater inflater;
    public MoreAdapter(Context context,List<MoreListDto> mMoreListDto){//Context context,
       this.context=context;
        this.mMoreListDto=mMoreListDto;
        this.inflater=LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mMoreListDto.size();
    }

    @Override
    public MoreListDto getItem(int position) {
        return mMoreListDto.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder=null;
        if(convertView==null){
            viewHolder= new ViewHolder();
            convertView=inflater.inflate(R.layout.list_more,parent,false);
            viewHolder.image1=(ImageView) convertView.findViewById(R.id.image1);
            viewHolder.text1=(TextView) convertView.findViewById(R.id.text1);
            viewHolder.root=(RelativeLayout) convertView.findViewById(R.id.root);
            viewHolder.asd = convertView.findViewById(R.id.and);
            viewHolder.bottom=convertView.findViewById(R.id.bottom);
            convertView.setTag(viewHolder);
        }else{
            viewHolder=(ViewHolder) convertView.getTag();
        }
        MoreListDto  moreListDto=getItem(position);
        if(moreListDto!=null){
            if(moreListDto.isShow()){
                viewHolder.asd.setVisibility(View.VISIBLE);
            }else{
                viewHolder.asd.setVisibility(View.GONE);
            }

            if(moreListDto.getTitle().equals("融资攻略")||moreListDto.getTitle().equals("在线客服")){
                viewHolder.bottom.setVisibility(View.VISIBLE);
            }
            viewHolder.image1.setImageResource(moreListDto.getIconIndex());
            viewHolder.text1.setText(moreListDto.getTitle());
        }
        return convertView;
    }


    class ViewHolder{
        ImageView image1;
        TextView text1;
        RelativeLayout root;
        View asd;
        View bottom;
    }

}
